class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        vector<int> ans;
        int ret, i, ans1, ans2 = 0;
        for (i = 0; i < nums.size(); i++) {
            ret ^= nums[i];
        }
        int k = 0;
        for (int j = 0; j < 32; j++) {
            if (ret & (1 << j)) {
                k = j;
                break;
            }
        }
        for (i = 0; i < nums.size(); i++) {
            if (nums[i] & (1 << k)) {
                ans1 ^= nums[i];
            }
            else {
                ans2 ^= nums[i];
            }
        }
        ans.push_back(ans1);
        ans.push_back(ans2);
        return ans;

    }

}
;